package com.alfayun.fiscalriskanalysis.articulation;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import com.alfayun.fiscalriskanalysis.util.IdsConverter;

@Entity
@Table(name = "articulation")
public class Articulation {
	
	@Column(name = "articulation_id", updatable = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Id
	private Integer id;
	public Integer leftUnitId;
	@Convert(converter = IdsConverter.class)
	public List<Integer> rightUnitIds;
	public String expressions;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public String getRightUnitIds() {
		return IdsConverter.joinList(rightUnitIds);
	}

	public void setRightUnitIds(String rightUnitIds) {
		this.rightUnitIds = IdsConverter.splitString(rightUnitIds);
	}
	
	public static Articulation newArticulation(ArticulationRepository repository, Articulation articulation) {
		articulation.id = 0;

		return repository.save(articulation);
	}

}
